package cn.lh.service.impl;

import cn.lh.domain.Product;
import cn.lh.domain.Store;
import cn.lh.dto.ProductDto;
import cn.lh.feignClient.StoreFeignClient;
import cn.lh.mapper.ProductMapper;
import cn.lh.service.IProductService;
import cn.lh.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class ProductServiceImpl implements IProductService {
    @Resource
    private ProductMapper productMapper;
    @Autowired
    StoreFeignClient storeFeignClient;

    @Override
    public JsonResult add(ProductDto productDto) {
        Product product = new Product(null, productDto.getName(), productDto.getPrice());
        productMapper.add(product);
        Store store = new Store(null, product.getId(), productDto.getNumber());
        return storeFeignClient.add(store);
    }

}
